<template>
  <div>
    <div class="toolbar">
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item>
          <el-input placeholder="商品类型名称" v-model="searchgoodsTypeName"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            @click="$store.dispatch('getGoodsTypeList',{searchName:searchgoodsTypeName})"
          >查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="success" @click="goodsTypeVisible=true">添加商品类型</el-button>
        </el-form-item>
      </el-form>
    </div>

    <el-table
      v-loading="$store.state.loading"
      :data="$store.state.goods.goodsTypeList"
      style="width: 100%"
    >
      <el-table-column label="店铺类别名称" width="120">
        <template slot-scope="scope">{{scope.row.shopTypeName}}</template>
      </el-table-column>
      <el-table-column label="店铺类别id" width="120">
        <template slot-scope="scope">{{scope.row._id}}</template>
      </el-table-column>
      <el-table-column label="店铺名称" width="120">
        <template slot-scope="scope">{{scope.row.shopName}}</template>
      </el-table-column>
      <el-table-column label="商品类别名称" width="120">
        <template slot-scope="scope">{{scope.row.goodsTypeName}}</template>
      </el-table-column>
      <el-table-column label="店铺添加时间" width="180">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 10px">{{ scope.row.createTime | date}}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" type="danger" @click="deleteList(scope.row._id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <GoodsTypeDialog :goodsTypeVisible.sync="goodsTypeVisible"></GoodsTypeDialog>
    <PageInfo action-name="getGoodsTypeList" :params="{goodsName:searchgoodsTypeName}"></PageInfo>
  </div>
</template>

<script>
import GoodsTypeDialog from "@/components/dialog/GoodsTypeDialog";
export default {
  name: "shop-list",
  components: {
    GoodsTypeDialog
  },
  data() {
    return {
      searchgoodsTypeName: "",
      goodsTypeVisible: false,
      goodsForm: {
        goodsName: "",
        goodsTypeId: ""
      }
    };
  },
  methods: {
    deleteList(id) {
      // console.log(id);
      this.$store.dispatch("deletegoodsTypeList", id).then(res => {
        if (res.ok === 1) {
          this.$store.dispatch("getGoodsTypeList", {
            goodsTypeName: this.searchgoodsTypeName,
            pageIndex: this.$store.state.pageIndex
          });
          this.$message({
            message: res.msg,
            type: "success"
          });
        } else {
          this.$message({
            showClose: true,
            message: res.msg,
            type: "error"
          });
        }
      });
    }
  }
};
</script>